#!/usr/bin/python
#coding:utf-8
'''
base64工具类
'''
import base64,os

def fileToBase64(file):
    '''
    图片转base64
    '''
    with open(file, 'rb') as fin:
        image_data = fin.read()
        image_base64 = str(base64.b64encode(image_data), encoding='utf-8')
        return image_base64

def base64ToFile(base64_data,image_url):
    '''
    base64转图片
    '''
    data = base64.b64decode(base64_data)
    with open(image_url, 'wb') as f:
        f.write(data)


